package org.veridiandynamics.server.domain;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Date;

/**
 * Appointment object which contains information about appointment (when, why, who).
 *
 */
public class Appointment implements PersistObject, Serializable 
{

	private Date startDate;
	private Date endDate;
	private String reason;
	private Invoice myInvoice;
	private long id;

	private static final long serialVersionUID = 30L;
	
	
	/**
	 * Constructor that takes in information to store that is critical to the instance of the object.
	 * 
	 * @param startDate
	 * @param endDate
	 * @param desiredReason
	 * @param myInvoice
	 */
	public Appointment(Date startDate, Date endDate, String desiredReason, Invoice myInvoice)
	{
	
		this.reason = desiredReason;
		this.startDate = startDate;
		this.endDate = endDate;
		this.myInvoice = myInvoice;
	}
	
	/**
	 * Default constructor.
	 */
	public Appointment()
	{
		
	}
	
	/**
	 * Sets the start date for an appointment.
	 * 
	 * @param desiredDate Date the scheduler would like an appointment to begin.
	 */
	public void setStartDate(Date desiredDate){
		this.startDate = desiredDate;
	}
	/**
	 * Sets the end date for an appointment. 
	 * @param desiredDate Date the scheduler would like an appointment to end.
	 */
	public void setEndDate(Date desiredDate){
		this.endDate = desiredDate;
	}
	/**
	 * Sets reason for appointment.
	 * 
	 * @param desiredReason Reason for appointment.
	 */
	public void setReason(String desiredReason){
		this.reason = desiredReason;
	}	
	/**
	 * Returns start of appointment.
	 * 
	 * @return start date Date object
	 */
	public Date getStartDate(){
		return startDate;
	}
	/**
	 * Returns end of appointment.
	 * 
	 * @return end date Date object
	 */
	public Date getEndDate(){
		return endDate;
	}

	/**
	 * Returns invoice object that is tied to the cost of appointment.
	 * 
	 * @return object of type Invoice
	 */
	public Invoice getMyInvoice() {
		return myInvoice;
	}

	/**
	 * Sets invoice for cost of particular appointment.
	 * 
	 * @param myInvoice object of type Invoice to be stored.
	 */
	public void setMyInvoice(Invoice myInvoice) {
		this.myInvoice = myInvoice;
	}
	/**
	 * Returns reason.
	 * 
	 * @return String containing reason for appointment.
	 */
	public String getReason(){
		return this.reason;
	}
	
	/**
	 * Returns ID for this object.
	 * @return variable of type long identifying object
	 */
	public long getId() {
		return id;
	}

	/**
	 * Sets the ID for this object. 
	 * @param id variable of type long identifying object
	 */
	public void setId(long id) {
		this.id = id;
	}
	/**
	 * Stores or writes object.
	 * 
	 * @param outputStream
	 * @throws IOException
	 */
	private void writeObject(ObjectOutputStream outputStream) throws IOException {
		outputStream.defaultWriteObject();
	}
	
	/**
	 * Reads object.
	 * 
	 * @param inputStream
	 * @throws ClassNotFoundException
	 * @throws IOException
	 */
	private void readObject(ObjectInputStream inputStream) throws ClassNotFoundException, IOException {
		inputStream.defaultReadObject();
	}

	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString()
	{
		String retVal = "";
		retVal += startDate.toString() + "\n";
		retVal += endDate.toString() + "\n";
		retVal += reason + "\n";
		return retVal;
	}
}
